//
//  ViewController.m
//  WebView
//
//  Created by 吴小明 on 2017/6/2.
//  Copyright © 2017年 qel. All rights reserved.
//

#import "ViewController.h"
#import "SecondViewController.h"

@interface ViewController ()

@end

//static NSString *webURL = @"http://www.baidu.com";
static NSString *webURL = @"http://192.168.1.132:8888/ADP_31/index4mobile.jsp";
static struct ScreenSize screenSize;

@implementation ViewController

- (void) viewDidLoad {
    
    [super viewDidLoad];
    
    //设置背景色为深灰
    self.view.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.8];

    [self getScreenSize];
    
    [self initialWebView: screenSize.width/2 withParamater:screenSize.height/2];
    
}

- (void) initialWebView : (int) width withParamater: (int) height{
    
    //初始化页面视图，并加入视图组中
    webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
    [self.view addSubview: webView];
    [self.navigationItem setTitle:@"三一重工质量管理系统"];
    //加载网页，把网页地址从NSURL格式转为NSURLRequest，再送进loadRequest进行加载
    NSURL *url = [NSURL URLWithString:webURL];
    [webView loadRequest:[NSURLRequest requestWithURL:url]];
    //页面自动适应屏幕尺寸，还没测试过。。。
    webView.scalesPageToFit = YES;
}

//获取屏幕像素尺寸，可调整view适应不同机型
- (void) getScreenSize {
    
    CGSize size_screen = [[UIScreen mainScreen]bounds].size;
    CGFloat scale_screen = [UIScreen mainScreen].scale;
    
    screenSize.width = (int) size_screen.width*scale_screen;
    screenSize.height = (int) size_screen.height*scale_screen;
    
    printf("设备屏幕宽度:%d \n", screenSize.width);
    printf("设备屏幕高度:%d \n", screenSize.height);

}


@end
